#!/usr/bin/env python
#coding=utf-8
import pika
import time
# rabbitmq-server    启动服务
# ######################### 生产者 #########################

connection = pika.BlockingConnection(pika.ConnectionParameters(
        host='localhost'))
channel = connection.channel()

channel.queue_declare(queue='hello')

for i in xrange(10):
    time.sleep(2)
    channel.basic_publish(exchange='',
                          routing_key='hello',
                          body='Hello World! i am {}'.format(i))
    print(" [x] Sent 'Hello World!'")
connection.close()

